/*
 * @Author: your name
 * @Date: 2020-05-18 17:47:33
 * @LastEditTime: 2020-05-21 18:01:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \v-nw-h5\src\store\modules\api\cloudPlay\room\mutations.js
 */ 
import Vue from 'vue';
export default {
    /*获取聊天室信息*/
    getChatRoom(state,obj){
        let roomId = obj && obj.roomId ? obj.roomId : 0;
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/cloud/play/chat/room/${roomId}/get`;
        Vue.prototype.xurl.postSync(url).then((data) => {
            if (data.success) {
                state.chatroomMsg = Object.assign({},state.chatroomMsg,data.result)
            } else if (data.errMsg) {
                console.log(data.errMsg)
            } else {
                console.log('获取聊天室信息失败')
            }
        })
    },
    /*进入聊天室*/
    enterChatRoom(state,obj){
        let roomId = obj && obj.roomId ? obj.roomId : 0;
        console.log(obj)
        console.log(obj,'enterChatRoomobj');
        let userId = obj.userId;
        let deviceType = 2;
        let deviceId = Vue.prototype.getDeviceId();
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/cloud/play/chat/room/${roomId}/enter?userId=${userId}&&deviceType=${deviceType}&&deviceId=${deviceId}`;
        Vue.prototype.xurl.put(url);
    },
    /*离开聊天室*/
    async leaveChatRoom(state,obj){
        let roomId = obj && obj.roomId ? obj.roomId : 0;
        let userId = obj.userId;
        let deviceType = 2;
        let deviceId = Vue.prototype.getDeviceId();
        let url = `${Vue.prototype.NW_API_API_LOCALE_VERSION}/cloud/play/chat/room/${roomId}/leave?userId=${userId}&&deviceType=${deviceType}&&deviceId=${deviceId}`;
        await Vue.prototype.xurl.putSync(url);
    },
}